import os
import re

class scanFile:

    def __init__(self, filePath):
        self.filePath = filePath

    def __openFile(self):
        with open(self.filePath, encoding="UTF-8") as f:
            self.content = f.read()
            # print(self.content)

    def __find(self):
        pattern = '"高二4班","(.*?)"'
        self.returnValue = re.findall(pattern, self.content)

    def __ending(self):
        print(self.returnValue)
        with open("./result.txt", 'w', encoding="UTF-8") as f:
            f.write(str(self.returnValue).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"))
            f.write("\n\n共" + str(len(self.returnValue)) + "位同学已完成青年大学习")

    def start(self):
        self.__openFile()
        self.__find()
        self.__ending()


if __name__ == "__main__":
    program = scanFile("C:/Users/Administrator/Desktop/table_1.xml")
    program.start()
    os.system("pause")
